package com.my.blog.website.config;

import io.netty.channel.Channel;
import io.netty.channel.group.ChannelGroup;
import io.netty.channel.group.DefaultChannelGroup;
import io.netty.util.concurrent.GlobalEventExecutor;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @author ：gyh
 * @date ：Created in 2021/2/6 13:22
 * @description：netty配置文件,管理channel组和用户对应channel
 * @modified By：gyh
 * @version: 1.0
 */
public class NettyConfig {
    /**
     * 定义一个channel组，管理所有的channel
     * GlobalEventExecutor.INSTANCE 是全局的事件执行器，是一个单例
     */
    private static ChannelGroup channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);


    /**
     * 存放用户与Chanel的对应信息，用于给指定用户发送消息
     */
    private static ConcurrentHashMap<String, Channel> userChannelMap = new ConcurrentHashMap<>();


    public NettyConfig() {
    }

    /**
     * @Author: gyh
     * @Description: 获取所有channel组
     * @DateTime: 2021/2/6 13:27
     * @Params: []
     * @Return io.netty.channel.group.ChannelGroup
     */
    public static ChannelGroup getChannelGroup(){
        return channelGroup;
    }

    /**
     * @Author: gyh
     * @Description: 获取用户对应的Channel组
     * @DateTime: 2021/2/6 13:28
     * @Params: []
     * @Return java.util.concurrent.ConcurrentHashMap<java.lang.String,io.netty.channel.Channel>
     */
    public static ConcurrentHashMap<String,Channel> getUserChannelMap(){
        return userChannelMap;
    }


}
